﻿#ifndef EXCELTHREAD_H
#define EXCELTHREAD_H

#include <QThread>
#include <QMap>
#include "utils/excelhandle.h"

QT_FORWARD_DECLARE_CLASS(LoadingWidget)
class ExcelThread : public QThread
{
    Q_OBJECT
public:
    enum ExcelOperatorType{
        ReadData =1,
        WriteData,
        NoOperator
    };

public:
    explicit ExcelThread(QString filename , ExcelOperatorType type =ExcelOperatorType::NoOperator ,QObject *parent = 0);

    void run();
    void setWriteDate(QMap<int,QString>);
    void setGroup(int);
    void setItemIndex(int value){m_ItemIndex=value;}
    void setExlHandle(const excelHandle &exlhdl){exlRecordHandle=exlhdl;}

signals:
    void startReadData(void);
    void finishedReadData(int/*Group number*/,QMap<int, QString>);

    void finishedWriteToSql(int,int);//groupnum and index

    void sig_finishedWithExlRecord(excelHandle);
public slots:

private slots:
    void finishedReadFromXls();
private:
    LoadingWidget *widgetLoad;
    QString m_filename;
    QMap<int, QString> m_map;

    QHash<int, QString> m_mapbox;
    QHash<int, QString> m_mapvalue;

    QMap<int, QString> m_mapWrite;

    ExcelOperatorType optType;
    int groupNum;
    int m_ItemIndex;

    excelHandle exlRecordHandle;//for write.

    int sem_i;
    QMutex mutex;
};

#endif // EXCELTHREAD_H
